package com.nami.store.biz.convertask.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nami.store.domain.ConverTaskDO;
import com.nami.store.mapper.ConverTaskMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.utils.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
@RequiredArgsConstructor
public class ConverTaskRepositoryImpl implements ConverTaskRepository {

    private final ConverTaskMapper baseMapper;

    @Override
    public Page<ConverTaskDO> getTask(Integer pageIndex, Integer pageSize) {
        return baseMapper.selectPage(new Page<>(pageIndex, pageSize), new QueryWrapper<ConverTaskDO>());
    }

    @Override
    public boolean batchDel(List<Long> ids) {
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    @Override
    public boolean addConverTask(String taskKey) {
        if (StringUtils.isBlank(taskKey)) {
            return false;
        }
        ConverTaskDO converTaskDO = new ConverTaskDO();
        converTaskDO.setTaskKey(taskKey);
        baseMapper.insert(converTaskDO);
        return Boolean.TRUE;
    }

    @Override
    public boolean batchSave(List<ConverTaskDO> addList) {
        baseMapper.insert(addList);
        return Boolean.TRUE;
    }

    @Override
    public boolean insert(List<ConverTaskDO> batchs) {
        baseMapper.insert(batchs);
        return Boolean.TRUE;
    }
}
